package com.situ.mybatis.utils;

import java.io.InputStream;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class MyBatisUtil {
	
	// 01.加载 输入流
	static InputStream inputStream = 
			MyBatisUtil.class.getResourceAsStream("/mybatis.xml");
	
	// 02.得到工厂
	static SqlSessionFactory factory= new SqlSessionFactoryBuilder().build(inputStream);
	
	// 1. 开启回话
	public static SqlSession opeSession() {
		return factory.openSession();
	}
	
	// 2. 关闭会话
	public static void closeSession(SqlSession session) {
		session.commit();
		session.close();
	}
}
